package com.hands.sample.baiduApi;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class ApiNlpDataHelper {


    /**
     * 解析语义，获取相关结果
     * @param speek
     * @param action
     * @return
     */
   public  static  String  nlpResult(String speek,String action){

       org.json.JSONObject obj =  AipNlpClass.handelString(speek);
       JSONArray arr = JSONArray.fromObject(obj.get("items").toString());
       String vPosItem = "";
       for (int i=0;i<arr.size();i++)
       {
           JSONObject myjObject = JSONObject.fromObject(arr.get(i));
           String pos = myjObject.get("pos").toString();
           if (action.equals(pos)){
               vPosItem = myjObject.get("item").toString();
               return   vPosItem;
           }

          /* JSONObject myjObject = JSONObject.fromObject(arr.get(i));
           String pos = myjObject.get("pos").toString();
           if (action.equals(pos) && !action.equals("m")) { //动词
               vPosItem = myjObject.get("item").toString();
               return  vPosItem;
           } else if (action.equals("m")) { //量词
               String[] basicWords = myjObject.get("basic_words").toString().replace("[", "").replace("]", "").split(",");
               *//*for (int j = 0; j < basicWords.length; j++) {
                   int num = TextConvertNumber.chineseNumber2Int(basicWords[j]);
                   System.out.println("转换数字为：" + num);
               }*//*

           }*/
           /*else if (action.equals("n") || action.equals("vn") || action.equals("nw")) { //名词等
               vPosItem = myjObject.get("item").toString();
           }*/
       }
       return  vPosItem;
   }

}
